#include <iostream>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <ctime>
#include <cstdlib>

using namespace std;

#define sz(x) ((int)((x).size()))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const double EPS = 1e-9;
const double PI = acos(-1.0);

struct Tree {
	int cnt;
	Tree *bl, *br, *tl, *tr;
	Tree(int cnt = 0, Tree *bl = NULL, Tree *br = NULL, Tree *tl = NULL, Tree *tr = NULL) {
		this->cnt = cnt;
		this->bl = bl;
		this->br = br;
		this->tl = tl;
		this->tr = tr;
	}
};

typedef Tree* node;

int getCnt(node t) {
	return (t == NULL ? 0 : t->cnt);
}

void update(node &t) {
	if (t == NULL)
		return;
	t->cnt = getCnt(t->bl) + getCnt(t->br) + getCnt(t->tl) + getCnt(t->tr);
}

void update(node &t, int lx, int rx, int ly, int ry, int x, int y) {
	if (t == NULL)
		t = new Tree();
	if (lx == rx && ly == ry) {
		t->cnt = 1;
	} else {
		int mx = (lx + rx) / 2;
		int my = (ly + ry) / 2;
		if (x <= mx) {
			if (y <= my) {
				update(t->bl, lx, mx, ly, my, x, y);
			} else {
				update(t->tl, lx, mx, my + 1, ry, x, y);
			}
		} else {
			if (y <= my) {
				update(t->br, mx + 1, rx, ly, my, x, y);
			} else {
				update(t->tr, mx + 1, rx, my + 1, ry, x, y);
			}
		}
		update(t);
	}
}

int getCnt(node &t, int lx, int rx, int ly, int ry, int x, int y) {
	if (t == NULL)
		return 0;
	if (lx > x || ly > y) {
		return 0;
	}
	if (rx <= x && ry <= y) {
		return getCnt(t);
	} else {
		int mx = (lx + rx) / 2;
		int my = (ly + ry) / 2;
		return getCnt(t->bl, lx, mx, ly, my, x, y) + getCnt(t->tl, lx, mx, my + 1, ry, x, y) + getCnt(t->br, mx + 1, rx, ly, my, x, y) + getCnt(t->tr, mx + 1, rx, my + 1, ry, x, y);
	}
}

struct MS {
	int x, y, z;
	int id;
	MS(int x, int y, int z, int id) : x(x), y(y), z(z), id(id) {}
	MS() : x(0), y(0), z(0), id(0) {}
};

bool cmp(MS a, MS b) {
		return a.x < b.x;
}

int n;
int N;
MS a[100500];

void solve() {
	scanf("%d", &n);
	N = 1;
	while (N < n) N *= 2;
	for (int i = 0; i < n; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		--x;
		--y;
		--z;
		a[i] = MS(x, y, z, i);
	}
	sort(a, a + n, cmp);
	int ans = 0;
	node t = NULL;
	for (int i = 0; i < n; i++) {
		if (getCnt(t, 0, N - 1, 0, N - 1, a[i].y, a[i].z) == 0) {
			ans++;
		}
		update(t, 0, N - 1, 0, N - 1, a[i].y, a[i].z);
	}
	printf("%d\n", ans);
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	int T;
	scanf("%d", &T);
	while (T-- > 0) solve();

	return 0;
}
